<template>
    <div class="system-user-dialog-container">
        <el-dialog :close-on-click-modal="false" width="20%" draggable v-model="visible">
            <el-form :model="dataForm" label-width="90px" ref="dataFormRef" v-loading="loading">
                <el-form-item :label="$t('bar.currentqty')" prop="currentqty">
                    <el-input clearable v-model="dataForm.currentqty"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
                    <el-button @click="onSubmit" type="primary" :disabled="loading">{{
                        $t('common.confirmButtonText')
                        }}</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts" name="spDialog" setup>
import { useMessage } from '/@/hooks/message';
import { getSpBarcode } from '/@/api/platform/wms/sp';
import { getAllMaterials, getAllProcess, getAllWarehouse, insertBarcode, getLocationLists } from '/@/api/platform/wms/reprintbarcode';
import { ref, reactive } from 'vue';

// 定义变量内容
const dataFormRef = ref();
const visible = ref(false);
const materialData = ref<any[]>([]);
const locationData = ref<any[]>([]);
const processData = ref<any[]>([]);
const warehousData = ref<any[]>([]);

const loading = ref(false);
const size = ref<'default' | 'large' | 'small'>('default');
import { useI18n } from 'vue-i18n';
const { t } = useI18n();

const dataForm = reactive({
    
});

// 打开弹窗
const openDialog = async (currentqty: string) => {
    visible.value = true;
    // 重置表单数据
    nextTick(() => {
        dataFormRef.value?.resetFields();
    });
    dataForm.currentqty=currentqty;
};

// 提交
const onSubmit = async () => {
    const valid = await dataFormRef.value.validate().catch(() => {
    });
    if (!valid) return false;

    try {
        loading.value = true;
        await insertBarcode(dataForm).then((res) => {
            if (!res.ok) {
                useMessage().error(res.data);
            }
        });
        visible.value = false; // 关闭弹窗
    } catch (error: any) {
        useMessage().error(error.msg);
    } finally {
        loading.value = false;
    }
};

// 暴露变量
defineExpose({
    openDialog,
});
</script>